package com.zc.im.seqsvr.handler;

import com.zc.im.seqsvr.business.SeqBusiness;
import com.zc.im.seqsvr.domain.Test;
import com.zc.im.seqsvr.repository.TestSeqRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

/**
 * Project：im
 * Date：2022/4/13
 * Time：19:19
 * Description：UserSeq对应处理器
 *
 * @author Challen.Zhang
 * @version 1.0
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class UserSeqHandler extends BaseHandler {

    private final SeqBusiness seqBusiness;

    private final TestSeqRepository repository;

    public Mono<ServerResponse> getSeqByUserId(ServerRequest request) {
        Long userId = Long.parseLong(request.pathVariable("userId"));
        return seqBusiness.getByUserId(userId).flatMap(this::ok);
    }

    public Mono<ServerResponse> createSeqByUserId(ServerRequest request){
        Long userId = Long.parseLong(request.pathVariable("userId"));
        return seqBusiness.createByUserId(userId).flatMap(this::ok);
    }
    public Mono<ServerResponse> test(ServerRequest request){
        Test test = new Test();
        test.setStatus(Test.StatusEnum.A);
        test.setNewObj(true);
        return repository.save(test).flatMap(this::ok);
    }

    public Mono<ServerResponse> test1(ServerRequest request){
        return repository.findById(1516766421907017728L).flatMap(this::ok);
    }

}
